import React, { Component } from "react";
import { createPortal } from "react-dom";

class Child extends Component {
  render() {
    // 将子组件渲染到父组件之外
    // createPortal方法传入两个参数，分别是组件和放的dom元素
    return createPortal(
      <div className="child">child组件</div>,
      document.querySelector("body")
    );
  }
}

class App extends Component {
  render() {
    return (
      <div className="abc">
        <h2>portal</h2>
        <Child />
      </div>
    );
  }
}

export default App;
